
**********
* Readme *
**********

* This script describes the general parameters and the set of required packages.


* Root folder (PATH TO BE DEFINED BY THE USER)
**********************************************
clear all
global analysis "C:/***/replication_package"


* General setup
***************
version 18
set varabbrev off, permanently
set more off, permanently
set matsize 5000, permanently
set maxvar 10000, permanently


* Required packages
*******************

* Save auxiliary libraries and programs within the project 
cap mkdir "${analysis}/code/project_ado/"
net set ado "${analysis}/code/project_ado/"
adopath ++ "${analysis}/code/project_ado/"

* Required packages
* net install datazoom_social, from("https://raw.githubusercontent.com/datazoompuc/datazoom_social_stata/master/") replace
* ssc install libjson
* ssc install insheetjson
* ssc install addplot
* ssc install unique
* ssc install estout
* ssc install gtools
* ssc install sxpose2
* net install texsave, from("https://raw.githubusercontent.com/reifjulian/texsave/master") replace
* net install epctile, from(http://staskolenikov.net/stata/) replace
* net install parallel, from(https://raw.github.com/gvegayon/parallel/stable/) replace
* ssc install coefplot
* ssc install survwgt
* ssc install ebalance
* ssc install qreg2
* ssc install splitvallabels
mata mata mlib index


* Graphical parameters (see file scheme-new.scheme)
***************************************************

discard
set scheme new, permanently
graph set eps fontface "Helvetica"


* Run the scripts
*****************

* Note: The step that reads POF microdata (1_1_read_pof_microdata.R) was build using R code from the data provider (IBGE) and for this reason it needs to be run on its own. All the remaining steps are performed with Stata.

* DATA IMPORT
* do "${analysis}/code/1_2_read_pnad_microdata.do" // computer intensive
* do "${analysis}/code/1_3_read_aux_files.do"

* DATA CLEANING
* do "${analysis}/code/2_1_build_pof_ind_attributes.do"
* do "${analysis}/code/2_2_build_pof_fam_inc_exp.do"
* do "${analysis}/code/2_3_build_pnad_attributes.do"
* do "${analysis}/code/2_4_reweight_pnad.do"
* do "${analysis}/code/2_5_build_pnad_duration.do"
* do "${analysis}/code/2_6_build_pnad_duration_appx_dom.do"

* DESCRIPTIVE EVIDENCE
* do "${analysis}/code/3_1_descriptive_plot.do"
* do "${analysis}/code/3_2_descriptive_pop_stats.do"
* do "${analysis}/code/3_3_descriptive_labor_status_stats.do"
* do "${analysis}/code/3_4_descriptive_labor_status_stats_appx_dom.do"

* ESTIMATIONS
* do "${analysis}/code/4_1_estimate_potential_wages.do"
* do "${analysis}/code/4_2_estimate_reservation_wages.do"
* do "${analysis}/code/4_3_estimate_duration_models.do" // computer intensive; includes routine for parallel computing but may take hours to run
* do "${analysis}/code/4_4_estimate_duration_models_appx_dom.do"
* do "${analysis}/code/4_5_estimate_duration_models_appx_rew.do"
* do "${analysis}/code/4_6_boot_wages_run.do"

* PUTTING THE PIECES OF THE MODEL TOGETHER
* do "${analysis}/code/5_model.do"
* do "${analysis}/code/6_rho_analysis.do"

* End of script
***************